﻿using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;

namespace BlazorLearn.Shared.Components;
public class RenderTester : ComponentBase
{
    public RenderTester()
    {
        Console.WriteLine($"-------{nameof(RenderTester)}构造函数---------");
    }

    public override Task SetParametersAsync(ParameterView parameters)
    {
        Console.WriteLine(nameof(SetParametersAsync));
        return base.SetParametersAsync(parameters);
    }

    protected override void OnInitialized()
    {
        Console.WriteLine(nameof(OnInitialized));
        base.OnInitialized();
    }

    protected override Task OnInitializedAsync()
    {
        Console.WriteLine(nameof(OnInitializedAsync));
        return base.OnInitializedAsync();
    }
    protected override void OnParametersSet()
    {
        Console.WriteLine(nameof(OnParametersSet));
        base.OnParametersSet();
    }

    protected override Task OnParametersSetAsync()
    {
        Console.WriteLine(nameof(OnParametersSetAsync));
        return base.OnParametersSetAsync();
    }

    protected override void OnAfterRender(bool firstRender)
    {
        Console.WriteLine("{0},{1}:{2}", nameof(OnAfterRender), nameof(firstRender), firstRender);
        base.OnAfterRender(firstRender);
    }

    protected override Task OnAfterRenderAsync(bool firstRender)
    {
        Console.WriteLine("{0},{1}:{2}", nameof(OnAfterRenderAsync), nameof(firstRender), firstRender);
        return base.OnAfterRenderAsync(firstRender);
    }

    protected override bool ShouldRender()
    {
        Console.WriteLine(nameof(ShouldRender));
        return base.ShouldRender();
    }

    protected override void BuildRenderTree(RenderTreeBuilder builder)
    {
        Console.WriteLine(nameof(BuildRenderTree));

        builder.OpenElement(0, "button");
        builder.AddAttribute(1, "class", "btn btn-primary");
        builder.AddAttribute(2, "onclick", EventCallback.Factory.Create(this, StateHasChanged));
        builder.AddContent(3, "刷新");
        builder.CloseElement();
    }
}
